//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public License
// along with this program.  If not, see http://www.gnu.org/licenses/.
// 

#ifndef __FINAL_SRC_H_
#define __FINAL_SRC_H_



#include <omnetpp.h>
#include  <stdio.h>
#include <string.h>
#include "Eth_pck_m.h"
#include "FBFrame_m.h"


/**
 * TODO - Generated class
 */
class Src : public cSimpleModule
{

	typedef struct RL{

		int si_count;
		int timer_scount;
		bool state;
		double crate;
		double trate;
		double tx_bcount;
		double timer;

	}RL;


private:
	cMessage *initial;
	cMessage *test;
	int firstDelay;
	int selfID;
	simtime_t nextDelay;
	simtime_t checkGate;
	cDatarateChannel *channel;
	cGate* g;
	RL rateLimiter;
	simtime_t chk;
	int ID;
	double maxRate;
	double bc_limit;
	double dec_factor;
	double GD;
	double MIN_DEC_FACTOR;
	double MIN_RATE;
	double TIMER_PERIOD;
	int FAST_RECOVERY_TH;
	double	R_HAI;
	double	R_AI;


protected:
	virtual void initialize();
	virtual void handleMessage(cMessage *msg);
    virtual void handleFB(FBFrame *fbFrame);
    virtual void timer_expired();
    virtual void self_increase();
    virtual int  MIN(int X,int Y);
    virtual void transFrame(Eth_pck *msg);
};

#endif
